<template>
  <div style="overflow:auto;position: relative;">
        <!-- 商品展示卡片 -->
        <div class="shop-list-box">
            <div class="shop-list">
                <div class="row" v-infinite-scroll="handleScroll" :infinite-scroll-disabled="disabled">
                    <div class="col-md-3" v-for="item in shopList" :key="item.id">
                        <el-card class="mycard">
                            <div class="shop-item">
                                <div class="shop-img">
                                    <img src="../../assets/images/shop/shop4.png" alt="" οnerrοr="javascript:this.src='../../assets/images/shop/shop4.png'">
                                </div>
                                <div class="shop-detail">
                                    <div class="shop-price">
                                        <div class="shop-price-warp">
                                            <div class="wrap-left">
                                                <span>{{item.stock}} </span>
                                                <i class="el-icon-star-off"></i>
                                            </div>
                                            <div class="wrap-right">${{item.price}}</div>
                                        </div>
                                    </div>
                                    <div class="shop-name">
                                        <div class="name nowrap">{{item.name}}</div>
                                        <div class="desc nowrap">{{item.detail}}</div>
                                    </div>
                                </div>
                                <div class="shop-operate">
                                    <el-button type="primary" size="medium" icon="el-icon-s-goods" style="width:100%;" @click="toShopDetail(item.id)"> 进 去 逛 逛</el-button>
                                </div>
                            </div>
                        </el-card>
                    </div>
                </div>   
                <div v-if="loading">加载中...</div>
            </div>
        </div>
    <!-- <ul
      class="list"
      v-infinite-scroll="handleScroll"
      :infinite-scroll-disabled="disabled">
      <li v-for="(i,index) in count" :key="index" class="list-item">{{ i }}</li>
    </ul>
    <p v-if="loading" class="box">加载中...</p>
    <p v-if="noMore">没有更多了</p> -->
  </div>
</template>

<script>
  export default {
    data () {
      return {
        count: 0,
        loading: false,
        // 获取商品列表请求参数
        shopListQuery:{
            pageNum: 1,
            pageSize: 8
        },
        // 商品列表
        shopList: [],
        // 商品总量
        total: 0
      }
    },
    computed: {
    //   noMore () {
    //     return this.count >= 100
    //   },
      disabled () {
        return this.loading || this.noMore
      }
    },
    methods: {
        // 获取商品列表
        async getShopList () {
            this.loading = true
            let map1 = {
                '':''
            }
            const { data: res } = await this.$http.post(`/product/solrSearch?pageNum=${this.shopListQuery.pageNum}&pageSize=${this.shopListQuery.pageSize}`,{params:{map: map1}})
            console.log('商品列表', res)
            if(res.code == 200){
                this.shopList = res.data.list
                this.total = res.data.total
                this.count = this.shopList.length
                console.log('商品列表', this.shopList)
            }
            this.loading = false
        },
        load () {
            this.loading = true
            setTimeout(() => {
            this.count += 5
            this.loading = false
            }, 2000)
        },
        // 判断滚到浏览器底部
        handleScroll(){
            var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
            var windowHeight = document.documentElement.clientHeight || document.body.clientHeight
            var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight
            //   console.log('scrollTop:',scrollTop,'--windowHeight:',windowHeight,'--scrollHeight',scrollHeight)
            if(Math.ceil(scrollTop + windowHeight) >= scrollHeight){
                // 请求接口
                if(this.count < this.total){
                    // this.load()
                    this.shopListQuery.pageSize += 8
                    this.getShopList()
                }
                console.log('到底了')
            }
        }
    },
    mounted(){
        // window.addEventListener('scroll', this.handleScroll)
        this.getShopList()
    }
  }
</script>


<style lang="scss" scoped>
.shop-list-box{
    min-width: 1200px;
    min-height: 550px;
    // background-color: #F8F8F8;
    padding: 20px 0;
    .shop-list{
        // height: calc(100% - 170px);
        // min-height: 500px;
        width: 1200px;
        margin: 0 auto;
        height: 100%;

    }
}

.mycard{
    transition: all 0.5s;
    margin-bottom: 2rem;
    // box-shadow: 0 4px 25px 0 rgba(0, 0, 0, 0.1);
}
.mycard:hover{
    transform:translate(0,-10px);
    box-shadow: 0 4px 25px 0 rgba(0, 0, 0, 0.2);
}
// 商品展示卡片
.shop-item{
    .shop-img{
        display: flex;
        justify-content: center;
        align-items: center;
        // height: 100%;
        min-height: 200px;
    }
    .shop-detail{
        padding: 0 1rem;
        .shop-price{
            .shop-price-warp{
                display: flex;
                justify-content: space-between;
                align-items: center;
                font-size: 0.95rem;
                .wrap-left{
                    color: #FFFFFF;
                    font-weight: 400;
                    background-color: #007bff;
                    padding: .15em .35em;
                    border-radius: .25rem;
                }
                .wrap-right{
                    font-weight: 700;
                }
            }
        }
        .shop-name{
            padding: 1.2rem 0;
            font-size: 0.8rem;
            .name{
                font-weight: 600;
                margin-bottom: 0.3rem;
            }
            .desc{
                font-weight: 300;
            }
            .nowrap{
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
        }
    }
    .shop-operate{
       
    }
}

.box{
    position: absolute;
    bottom: 0;
}
</style>